/**
 * Created by d on 2015/12/21.
 */

define(function (require, exports, module) {
    'use strict'
    
    var rk = require('rk');

    require('platform/core/css/all-xsy-widgets.css')
    require('crm/js/apps/crm/crm');
    var constant = require('crm/js/apps/common/constant');
    require('oa/js/su/oa_list')


    $.widget('rk.schedule', $.rk.oa_list,  {
        _create : function(){
            var me = this,
                elem = me.element,
                opt = me.options;
        },

        _init : function(){
            var me = this,
                elem = me.element,
                opt = me.options;

            var layoutHtml = rk.templateText(require('page/tmpl/schedule/list_layout.tpl'), {});
            elem.html(layoutHtml);
            var $contentEle = elem.find('div.xsy_oa_detail_body');
            $contentEle.newTaskList({
                    //account 229909
                business: constant.belongIdToBusinessName[rk.getUrlParam('fromBelongId')],
                businessId: rk.getUrlParam('fromDataId'),
                name : decodeURIComponent(rk.getUrlParam('name'))
            });
            me._addEventListener();
            me.setTitle();
        },

        _addEventListener : function(){
            var me = this,
                elem = me.element,
                opt = me.options;

            elem.on('click', 'a.xsy_oa_detail_create', function(){
                var config = {
                    isAllDay: false,
                    act: 'create',
                    ownerUser: SESSION.user,
                    entityId : rk.getUrlParam('fromBelongId'),
                    sourceEntity : {
                        id : rk.getUrlParam('fromDataId'),
                        name : rk.getUrlParam('name')
                    },
                    success : function(){
                        setTimeout(function(){
                            window.location.reload(true);
                        }, 1000);
                    }
                };
                var scheduleUtil = require('oa/js/schedule/asset/utils/scheduleUtil')
                scheduleUtil.popupEditor(config);
            });
        }

    });

    module.exports = {
        init : rk.crm.initPanel
    }

});
